package com.tl.libpay.wx;

import android.app.Activity;
import android.util.Log;

import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
/**
 * @author JongSung
 * @Description 微信支付逻辑
 * @date 2017/8/30 0022
 */
public class PayWX {
    private Reference<Activity> activity;
    private IWXAPI api;

    public PayWX(Activity activity) {
        this.activity = new WeakReference<>(activity);
    }



    public void wxPay(String partnerId,String prepayId,String nonceStr,String timeStamp,String sign) {
        final Activity act = activity.get();
        api = WXAPIFactory.createWXAPI(act, Constants.APP_ID);
        api.registerApp(Constants.APP_ID);
        PayReq request = new PayReq();
        request.appId = Constants.APP_ID;
        request.partnerId = partnerId;
        request.prepayId= prepayId;
        request.packageValue = "Sign=WXPay";
        request.nonceStr= nonceStr;
        request.timeStamp= timeStamp;
        request.sign= sign;
//        Log.i("wechatPay参数","appId"+Constants.APP_ID+"partnerId"+partnerId
//        +"prepayId"+prepayId+"nonceStr"+nonceStr+"timeStamp"+timeStamp
//                +"sign"+sign);
        api.sendReq(request);


    }


}
